#include "Cpu.H"
#include "app.H"
#include "kernel.H"
//#include "module.H"

union SYSBIT_1 SysBit_1;
union SYSSTS1  SysSts1;
union LCLBTNSTS1 LclBtnSts1;
union FLASH_SAVE FlashSave;
union FT_CTR_BTN FtCtrBtn;
union FT_CTR_BTN FtCtrBtnOld;


struct  MEM_PLACE MemPlace;
MEM_PLACE_ANGLE CurrPst;
MEM_PLACE_ANGLE RecordPst;

struct DOCTOR Doctor;

struct MAINBRDDATA MainBrdData;


static __IO uint32_t TimingDelay;


void Delay(__IO uint32_t nTime);


int main(void)
{
	sInitialMCU();
	
	OSInit();
 
	//Create tasks and initial Task's timer
	OSTaskCreate(sSuperTask,MAX_SUPERJOB_STK_SIZE,cPRIO_SUPERJOB);
	OSTimerStart(cPRIO_SUPERJOB,0,2); // cT2ms
	OSTaskCreate(sGenEventTask,MAX_GENEVENTJOB_STK_SIZE,cPRIO_GENEVENTJOB);
	OSTimerStart(cPRIO_GENEVENTJOB,1,4); //cT4ms
	OSTaskCreate(sSciTask,MAX_SCIJOB_STK_SIZE,cPRIO_SCIJOB);
	OSTimerStart(cPRIO_SCIJOB,0,50); //cT50ms
	
	OSStart();
}


void Delay(__IO uint32_t nTime)
{ 
  TimingDelay = nTime;

  while(TimingDelay != 0)
	{
	}
}

void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  { 
    TimingDelay--;
  }
}

